<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/publicPage.jsp"%>
<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>手机用户管理</title>
    <%@ include file="/publicIcon.jsp"%>
    <%@ include file="/publicLigerUI.jsp"%>
    <%@ include file="/publicGridJS.jsp"%>
    <script type="text/javascript">
        function itemclick(item)
        {
            alert(item.text);
        }

        var gridManager,win1 ;

        $(function ()
        {
            //布局
            $("#layout").ligerLayout({ leftWidth: 190, height: '80%',heightDiff:-34,space:4 });
            gridManager =
                $("#maingrid").ligerGrid({
                    height:'100%',
                    checkbox: true,
                    width:'100%',
                    columns: [
                        { display: 'id', name: 'messageTableId',hide:true,width: '0%'},
                        { display: '信息随机id', name: 'messageId',hide:true,width: '0%' },
                        { display: '信息头', name: 'messageHead', width: '11.4%' },
                        { display: '信息体', name: 'messageBody', width: '88.4%' },
                    ],url:'/rest/information/messageList',  pageSize:30 ,rownumbers:true,

                    //单击事件
                    onSelectRow:function(column, rowindex){
                        //alert(column.remark);
                        //alert(rowindex);
                    },

                    //双击行调到修改页面(获得ID当参数)
                    onDblClickRow:function(column, rowindex){
                        f_edit(column.id);
                    },

                    toolbar: { items: [
                            { text: '添加', click: function(item){
                                    f_Create();
                                }, icon: 'add' },
                            { line: true },
                            { text: '修改', click: function(item){
                                    f_Update();
                                }, icon: 'modify' },
                            { line: true },
                            { text: '删除', click: function(item){
                                    f_Delete();
                                }, icon:'delete'},
                            { line: true },
                        ]
                    }
                });
            $("#pageloading").hide();
        });


        //测试获取隐藏colunmns的属性
        function testHide(){
            var grid = jQuery("#maingrid").ligerGrid();
            $.ajax({
                type:"POST",
                url:'${pageContext.request.contextPath}/rest/style/createStyle',
                data: $('#form1').serialize(),
                async: false,
                success: function (data) {
                    /* window.parent.okdialog();
                    window.parent.loadData();
                    window.parent.closeDialog(); */
                },
                error: function (request) {
                    /* $.ligerDialog.error('添加失败！', function ()
                {
                        window.parent.loadData();
                        window.parent.closeDialog();
                }) */
                }
            });
            for (i = 2; i < grid.columns.length; i++) {
                if (grid.columns[i]._hide != true && grid.columns[i]._hide != "true") {
                    /* alert(grid.columns[i].display+"+======"+grid.columns[i]._hide); */
                }else{
                    /* alert(grid.columns[i].display+"+======"+grid.columns[i]._hide); */
                }
            }
        }

        function f_heightChanged(options)
        {
            if (tab)
                tab.addHeight(options.diff);
            if (accordion && options.middleHeight - 24 > 0)
                accordion.setHeight(options.middleHeight - 24);
        }
        //添加
        function f_Create()
        {
            win1 = $.ligerDialog.open({
                url: '/rest/information/doAddMessage',
                title:"添加",
                width: 850,
                height:350,
                showMax: false,
                showToggle: true,
                showMin: false,
                isResize: true,
                slide: false
            });
        }
        //修改
        function f_Update()
        {
            var selRow = gridManager.getSelecteds();//返回选中行数，如果选中多于一行提示:不能同时修改多行！
            if(selRow.length>=2){
                $.ligerDialog.warn('您已选中多行数据,请确定需要修改的一行记录!');
                return false;
            }
            //如果没有选，则提示：请选中一行!
            var selected = gridManager.getSelected();
            if (!selected) {
                $.ligerDialog.error('请选中一行!');
                return;
            }
            win1 = $.ligerDialog.open({
                url: '/rest/information/messageById?id='+selected.messageTableId,
                title:"修改信息",
                width: 850,
                height:350,
                showMax: false,
                showToggle: true,
                showMin: false,
                isResize: true,
                slide: false
            });
        }

        //双击行后调到修改页面,按传过来的ID
        function f_edit(id)
        {
            win1 = $.ligerDialog.open({
                url: '/rest/information/messageById?id='+id,
                title:"修改信息",
                width: 850,
                height:350,
                showMax: false,
                showToggle: true,
                showMin: false,
                isResize: true,
                slide: false
            });
        }
        //删除
        function f_Delete()
        {
            //如果没有选，则提示：请选中一行!
            var selected = gridManager.getSelected();
            if (!selected) {
                $.ligerDialog.error('请选中一行!');
                return;
            }
            $.ligerDialog.confirm('你确定要删除吗?', function (yes){
                var selRow = gridManager.getSelecteds();//返回选中多行
                var id="";
                for(var i=0;i<selRow.length;i++){
                    id+=selRow[i].messageTableId+",";
                }
                if(yes){
                    $.ajax({ url: "/rest/information/messageDel?id=" +id,
                        type: "post",
                        contentType:"charset=utf-8",
                        success: function(result){
                            gridManager.loadData();
                            gridManager.closeDialog();
                        },
                        error: function (request) {
                            window.parent.nodialog();
                        }
                    });
                }
            });
        }

        //grid刷新
        function loadData(){
            gridManager.loadData();
        }

        //关闭子窗口
        function closeDialog(){
            if(win1){win1.close();}
        }

        //成功操作
        function okdialog(){
            $.ligerDialog.success('操作成功!');
        }

        //失败操作
        function nodialog(){
            $.ligerDialog.error('操作失败!');
        }

        //关闭子窗口from
        function closeFrom(){
            win1.close();
        }
        //按条件查询
        $(function(){
            $("#Button1").ligerButton({
                click: function () {
                    //重置查询页数，从第一页开始
                    gridManager.set({ page: 1, newPage: 1 });
                    //设置Ajax参数
                    gridManager.setParm("messageHead", $("#txtKey").val());
                    //重新请求
                    gridManager.loadData(gridManager.url);
                }
            });
        });
    </script>
</head>
<body>
<div id="layout">
    <div  title="消息列表">
        <ul>
            <li style="margin:10px">
                消息头：
                <input class="input" name="txtKey" type="text" id="txtKey" ltype="text" />&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="submit"  value="查询" id="Button1" class="l-button l-button-submit" />
            </li>
        </ul>
        <div id="maingrid"></div>
    </div>
    <div style="display: none;">
    </div>
</div>
</body>
</html>